<?php

namespace App\Services\TransferApple;

use App\Models\User;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

class TransferApple
{
	/**
	 * @var User
	 */
	protected $self;

	/**
	 * @var User
	 */
	protected $guser;

	protected $apples = 0;

	public function __construct(User $self, User $guser, $apples)
	{
		$this->self = $self;
		$this->guser = $guser;
		$this->apples = $apples;
	}

	protected function transfer()
	{
		DB::transaction(function () {
			$data = ['gift_user_id' => $this->guser->id];
			account_apples($this->self)->minusGiftApples($this->apples, $data,$this->guser->name);

			$data = ['parent_user_id' => $this->self->id];
			account_apples($this->guser)->plusGetApples($this->apples, $data,$this->self->name);
		});
	}

	public function apply()
	{

		$this->transfer();
	}
}
